<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('../includes/auth.inc.php');
}

if (isset($_POST['ed_updated'])) {

	// check to see if details have been completed
	if (empty($_POST['ed_thanks']) || empty($_POST['ed_approve']) || empty($_POST['ed_reciprocal']) || empty($_POST['ed_new']) || empty($_POST['ed_signature'])) {
	$error = 1;

	} else {
	
	$sql = sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'emailThanks'",
			   quote_smart($_POST['ed_thanks']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'emailApprove'",
			   quote_smart($_POST['ed_approve']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'emailNoRecip'",
			   quote_smart($_POST['ed_reciprocal']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'emailNewLink'",
			   quote_smart($_POST['ed_new']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'emailSig'",
			   quote_smart($_POST['ed_signature']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	
	
	}
}

$getUserDetails = mysql_query("SELECT * FROM affiliSt_config");
$userDetails = mysql_fetch_assoc($getUserDetails);

?>


<?php
// error report
if ($error == 1) {
echo '<fieldset><strong style="color:red">ERROR: Fields must not be empty</strong></fieldset>';
} else {
	if (isset($_POST['ed_updated'])) {
	echo '<fieldset><strong style="color:green">Email Templates Updated</strong></fieldset>';
	}
}
?>



<fieldset>
<legend>Edit Email Templates</legend>
<form action="index.php?ad=lde" method="post" name="updateDetails">

<table cellpadding="4" cellspacing="0" border="0">
<?php do { ?>
<?php if ($userDetails['name'] == 'emailThanks') { ?>
<tr>
<td align="left" valign="top">
<label for="edThanks">Thank You Email:</label>
</td>
<td align="left" valign="top">
<textarea name="ed_thanks" id="udThanks" rows="6" class="adminInput"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'emailApprove') { ?>
<tr>
<td align="left" valign="top">
<label for="udApprove">Approved Link Email:</label>
</td>
<td align="left" valign="top">
<textarea name="ed_approve" id="udApprove" rows="6" class="adminInput"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'emailNoRecip') { ?>
<tr>
<td align="left" valign="top">
<label for="udReciprocal">No Reciprocal Link:</label>
</td>
<td align="left" valign="top">
<textarea name="ed_reciprocal" rows="6" id="udReciprocal" class="adminInput"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'emailNewLink') { ?>
<tr>
<td align="left" valign="top">
<label for="udNew">New Link Email:</label>
</td>
<td align="left" valign="top">
<textarea name="ed_new" id="udNew" rows="6" class="adminInput"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'emailSig') { ?>
<tr>
<td align="left" valign="top">
<label for="udSignature">Email Signature:</label>
</td>
<td align="left" valign="top">
<textarea name="ed_signature" id="udSignature" rows="6" class="adminInput"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php } while ($userDetails = mysql_fetch_assoc($getUserDetails)); ?>
</table>
<input type="hidden" name="ed_updated" value="yes" />
<input value="Edit Email Templates" type="submit" class="padSubmit" />
</form>
</fieldset>